//index.js
const app = getApp()

Page({
  data: {
    navbarArr: [{
        pic_url: 'http://sd.offcn.com/zg/wximg/gkhz-img/icon_1.png',
        viewNavto: 'to3',
        name: '进面名单查询'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/gkhz-img/icon_2.png',
        viewNavto: 'to3',
        name: '面试考情查询'
      },

      {
        pic_url: 'http://sd.offcn.com/zg/wximg/gkhz-img/icon_7.png',
        viewNavto: 'to5',
        name: '晒分查排名'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/gkhz-img/icon_8.png',
        viewNavto: 'to6',
        name: '面试考场还原'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/gkhz-img/icon_3.png',
        viewNavto: 'to6',
        name: '面试解读峰会'
      },
      {
        pic_url: 'http://sd.offcn.com/zg/wximg/gkhz-img/icon_4.png',
        viewNavto: 'toxiaoneng',
        name: '国考问题咨询'
      },
    ],
    theSwiper: [{
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/new.jpg',
        tomini: 'tozx'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_2.jpg',
        tomini: 'tozx'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_3.jpg',
        tomini: 'togkbs'
      },
      {
        src: 'http://sd.offcn.com/zg/wximg/gkhz-img/banner_4.jpg',
        tomini: 'to19'
      }
    ],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 3000,
    duration: 1500,
    current: 0,
    area: '默认',
    geneal: '默认'
  },
  to1: function () {
    wx.navigateTo({
      url: '../question/question?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  to2: function () {
    wx.navigateTo({
      url: '../search/search?area='  + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  to3: function () {
    wx.switchTab({
      url: '../query/query'
    })
  },
  to4: function () {
    wx.navigateTo({
      url: '../fsx/fsx?area=' + this.data.area + '&agent=' + this.data.geneal + '&page=' + this.data.page
    })
  },
  to5: function () {
    wx.navigateToMiniProgram({
      appId: 'wx58c52a1b32912237', //模考appid
      path: 'pages/sfs/sfs?data={"zwcode":"gj","zwyear":"2021","area":"sd","scode":"xyl14609"}', //模考
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  toMiniProgram: function() {
    wx.navigateToMiniProgram({
        appId: "wx2eec5fb00157a603",
        path: "fangkongfuwu/pages/healthCode/step_1/index?eid=YQ_WJW_FYJKXXM%2CGSS_YQ",
        extraData: {
            foo: "bar"
        },
        envVersion: "release",
        success: function(e) {}
    });
},
toMiniProgram2: function() {
  wx.navigateToMiniProgram({
      appId: "wx8f446acf8c4a85f5",
      path: "pages/index",
      extraData: {
          foo: "bar"
      },
      envVersion: "release",
      success: function(o) {}
  });
},
  to6: function () {
    wx.navigateToMiniProgram({
      appId: 'wxca86930ec3e80717', //模考appid
      path: 'page/course/details?fenxiang=1&id=221858', //模考
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  link1: function () {
    wx.navigateToMiniProgram({
      appId: 'wxca86930ec3e80717', //模考appid
      path: 'page/course/details?fenxiang=1&id=221858', //模考
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  link2: function () {
    wx.navigateTo({
      url: '../wen2/wen2',
    })
  },
  link3: function () {
    wx.navigateTo({
      url: '../wen3/wen3',
    })
  },
  toxiaoneng: function () {
    wx.navigateTo({
      url: '../xiaoneng/xiaoneng'
    })
  },
  toshijuan: function () {
    wx.navigateToMiniProgram({
      appId: 'wx3dec2f3a28471026', //国考职位查询小程序appid
      path: 'pages/index/index?source=sharelock&minicodeid=377177', //国考职位查询首页index
      envVersion: 'release', //develop（开发版），trial（体验版），release（正式版） 
      success(res) {
        console.log('打开成功！')
      }
    })
  },
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent,
      page: options.page
    })
    wx.setStorageSync('area', options.area)
    wx.setStorageSync('agent', options.agent)

    var d = new Date()
    that.setData({
      sheng: 29 - d.getDate()
    })
  },
  swiperChange: function (e) {
    var that = this;
    if (e.detail.source == 'touch') {
      that.setData({
        current: e.detail.current,
      })
    }
  },
  getPhoneNumber(e) {
    var that = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      that.setData({
        mobile: res.result,
      })
      wx.setStorage({
        key: "phone",
        data: res.result
      })
      try {
        var value = wx.getStorageSync('phone')
        if (value) {
          this.setData({
            "navbarArr[0].opentype": 'false',
            "navbarArr[2].opentype": 'false',
            "navbarArr[3].opentype": 'false',
            "navbarArr[7].opentype": 'false',
          });
        }
      } catch (e) {
        // Do something when catch error
      }
      console.log(res.result)
      console.log('cloud phone get success!')
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=21474&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: that.data.area,
          geneal: that.data.geneal,
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log('zg99 phone get success !')

        }
      })

      wx.redirectTo({
        url: '../index/index'
      })

    }).catch(err => {
      console.error(err);
    });



  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '2021国家公务员智能职位检索系统 '
    }
  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    var that = this;
    var id = wx.getStorageSync('id')
    return {
      title: '2021国家公务员智能职位检索系统',
      path: 'pages/index/index'
    }
  }


})